import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;

public class ExecutorServiceMain {

	public static void main(String[] args) throws InterruptedException {
		ExecutorService pool = Executors.newFixedThreadPool(7);
		for (int i = 0; i < 7; i++) {
			final int j = i;
			pool.execute(new Runnable() {

				public void run() {
					try {
						while (true) {
							System.out.print(j + " ");

							Thread.sleep(1000);
						}
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			});
		}
		Thread.sleep(5000);
		pool.shutdownNow();
	}

}
